package com.gai.shop.web.controller;

import com.gai.shop.common.Const;
import com.gai.shop.entity.Orders;
import com.gai.shop.service.OrdersService;
import com.gai.shop.service.impl.OrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class AdminOrderController extends BaseController {
    private final OrdersService OS = new OrdersServiceImpl();

    /**
     *
     * @param request
     * @param response
     * @return
     * @throws ServletException
     * @throws IOException
     */
    public String getAllOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取的参数
        String uname = request.getParameter("uname");
        String ostate = request.getParameter("ostate");

        //访问业务层 获取数据
        List<Orders> allOrders = OS.getAllOrders(uname, ostate);
        request.setAttribute(Const.UserConst.ORDER_LIST,allOrders);
        return Const.FORWARD + "/admin/showAllOrder.jsp";
    }

    /**
     *
     * @param request
     * @param response
     * @return
     * @throws ServletException
     * @throws IOException
     */
    public String sendOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oid = request.getParameter("oid");
        //访问业务层进行数据的修改
        OS.updateOrderStateToSend(oid,Const.OrderConst.ORDER_SEND);
        return  Const.REDIRECT + "/admin_order?method=getAllOrder";
    }
}
